package com.kbplus.demo.data.permission.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kbplus.demo.data.permission.entity.Department;
import com.kbplus.demo.data.permission.mapper.DepartmentMapper;
import com.kbplus.demo.data.permission.service.DepartmentService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * (Department)表服务实现类
 *
 * @author kbplus
 * @since 2022-05-13 10:32:29
 */
@Service("departmentService")
public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Department> implements DepartmentService {

    @Override
    public List<String> getDeptChildren(String deptId){
        ArrayList<String> depts = new ArrayList<>();
        depts.add(deptId);
        getDeptChildrenByDeptId(deptId,depts);
        return depts;
    }

    private void getDeptChildrenByDeptId(String deptId,List<String> depts){
        List<String> deptChildren = baseMapper.getDeptChildrenById(deptId);
        if(CollectionUtil.isEmpty(deptChildren)){
            return;
        }
        depts.addAll(deptChildren);
        for (String childId : deptChildren) {
            getDeptChildrenByDeptId(childId,depts);
        }

    }

}

